#include "StdAfx.h"
#include "AIDPidlManager.h"

AIDPidlManager::AIDPidlManager(void)
{
}

AIDPidlManager::~AIDPidlManager(void)
{
}

HRESULT AIDPidlManager::createRoot(AID_APP_TYPE appType, LPITEMIDLIST* p)
{
	HRESULT hr = S_OK;
	WCHAR szTmp[64] = {0, };
	size_t tmpSize = 64 * sizeof (WCHAR);

	switch(appType)
	{
	case AID_FOLDER_TYPE_FAVORITES:
		StringCbCopy(szTmp, tmpSize, L"Favorites");
		break;
	case AID_FOLDER_TYPE_FTP:
		StringCbCopy(szTmp, tmpSize, L"FTP");
		break;
	case AID_FOLDER_TYPE_SSH:
		StringCbCopy(szTmp, tmpSize, L"SSH");
		break;
	case AID_FOLDER_TYPE_SVN:
		StringCbCopy(szTmp, tmpSize, L"SVN");
		break;
	case AID_FOLDER_TYPE_MAIL:
		StringCbCopy(szTmp, tmpSize, L"Mail");
		break;
	default:
		hr = E_FAIL;
	break;
	}
	
	if (FAILED (hr))
		return hr;
	
	size_t len = 0;
	StringCbLength(szTmp, tmpSize, &len);
	size_t fullLength = len * sizeof(WCHAR);
	fullLength	+= 	sizeof(AID_ITEM_TYPE) + sizeof(AID_APP_TYPE) + sizeof(AID_ATTR);

	LPAIDPIDL	newPidl;
	LPBYTE pTmp = (LPBYTE)_AtlModule.getAllocator()->Alloc(len);
	newPidl = reinterpret_cast<LPAIDPIDL>(pTmp);

	newPidl->attr		= AID_ATTR_EXEC | AID_ATTR_READ | AID_ATTR_WRITE;
	newPidl->origApp	= appType;
	newPidl->type		= AID_ROOT_FOLDER;
	StringCbCopy(newPidl->szName, len * sizeof (WCHAR), szTmp);

	return hr;
}

HRESULT AIDPidlManager::createChild(LPCITEMIDLIST parent, LPCWSTR name, AID_ATTR attributes)
{
	HRESULT hr = S_OK;
	if (parent == NULL)
	{
		//we have the root, so we will create a new one
	}
	return hr;
}